package com.hl.unittestlearn.di.module;

import com.hl.unittestlearn.http.APIServiceManager;
import com.hl.unittestlearn.http.APIService;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2016/12/28 0028.
 */
@Module
public class ApplicationModule {

    @Singleton
    @Provides
    public APIServiceManager providesAPIManager(APIService apiService)
    {
        return APIServiceManager.initAPIManager(apiService);
    }

    @Provides
    @Singleton
    public APIService providesAPIService()
    {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(APIServiceManager.BASE_URL)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .client(new OkHttpClient())
                .build();

        return  retrofit.create(APIService.class);
    }
}
